function isEmpty(val) {
	if (val == null) return true;

	if (typeof val === 'boolean') return false;

	if (typeof val === 'number') return !val;

	if (val instanceof Error) return val.message === '';

	switch (Object.prototype.toString.call(val)) {
		// String or Array
		case '[object String]':
		case '[object Array]':
			return !val.length;

			// Map or Set or File
		case '[object File]':
		case '[object Map]':
		case '[object Set]':
			{
				return !val.size;
			}
			// Plain Object
		case '[object Object]':
			{
				return !Object.keys(val).length;
			}
	}

	return false;
}

// 位置1：纬度，经度  位置2：纬度，经度
function getDistance(la1, lo1, la2, lo2) {
	la1 = la1 || 0;
	lo1 = lo1 || 0;
	la2 = la2 || 0;
	lo2 = lo2 || 0;

	var La1 = la1 * Math.PI / 180.0;
	var La2 = la2 * Math.PI / 180.0;
	var La3 = La1 - La2;
	var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
	var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 /
		2), 2)));
	s = s * 6378.137;
	s = Math.round(s * 10000) / 10000;
	s = s.toFixed(2);
	return s;
}

// 过去时间计算
function fromTimer(time) {
	var timer = (new Date()).getTime() - (time * 1000);
	timer = parseInt(timer / 1000);
	if (timer < 180) {
		return '刚刚';
	} else if (timer >= 180 && timer < 3600) {
		return parseInt(timer / 60) + '分钟前';
	} else if (timer >= 3600 && timer < 86400) {
		return parseInt(timer / 3600) + '小时前';
	} else if (timer >= 86400 && timer < 2592000) {
		return parseInt(timer / 86400) + '天前';
	} else {
		return this.formatDateTime(time, 'str');
	}
}

function findIndexInfo(list, id, idKey){
	let index
	if(isEmpty(idKey)){
		index = list.findIndex(item=>item == id)
	} else {
		index = list.findIndex(item=>item[idKey] == id)
	}
	console.log(index)
	return list[index]
}
//图片转换base64
function	urlToBase64(url){
	let imgBase64 = wx.getFileSystemManager().readFileSync(url, "base64"),
	base64Url = `data:image/png;base64,${imgBase64}`;
	return base64Url;
}

export {
	isEmpty,
	getDistance,
	fromTimer,
	findIndexInfo,
	urlToBase64
}
